package com.yc.tc.times;

import java.util.Timer;
import java.util.TimerTask;
import javax.servlet.http.HttpSession;
import com.yc.tc.utils.SessionAttributeNames;
public class MyTimer {
	private TimerTask task=null;
	private Timer timer=new Timer();
	
	public void getTimeer(final HttpSession session){
		task=new TimerTask() {
			
			@Override
			public void run() {
				session.setAttribute(SessionAttributeNames.CHECKCODE, "");
				session.removeAttribute(SessionAttributeNames.CHECKCODE);
				//System.out.println("session清空完成...");
			}
		};
		
		timer.schedule(task, 60*1000);  //1分钟执行此方法一次
	}
	
	public void closeTimer(){
		if(timer!=null){
			timer.cancel();
		}
		
		if(task!=null){
			task.cancel();
		}
	}
	
}

